package it.unibo.refolding.pico;

import it.unibo.refolding.pico.PicoDataAnalyser.ContactPointAndSlope;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public class RetractionTrace {
    private final String path;
    private final double deflectionLsbToMetresFactor, zLsbToMetresFactor;
    private final ContactPointAndSlope cps;
    private final List<DirectionData> segments;

    public RetractionTrace(String path, double deflectionLsbToMetresFactor,
        double zLsbToMetresFactor, ContactPointAndSlope cps, List<DirectionData> segments) {
        this.path = path;
        this.deflectionLsbToMetresFactor = deflectionLsbToMetresFactor;
        this.zLsbToMetresFactor = zLsbToMetresFactor;
        this.cps = cps;
        this.segments = segments;
    }

    public String repr() {
        return String.format(
            Locale.ROOT, "RetractionTrace(r'%s', %s, %s, %s, %s)", path,
            Double.toString(this.deflectionLsbToMetresFactor), Double.toString(zLsbToMetresFactor),
            cps != null ? cps.repr() : "None", repr(segments));
    }

    private String repr(List<DirectionData> segments) {
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (DirectionData segment : segments) {
            sb.append(String.format(
                Locale.ROOT, "DirectionData(%s, %s), ", Arrays.toString(segment.deflection),
                Arrays.toString(segment.z)));
        }
        sb.append(']');
        return sb.toString();
    }
}
